﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using ExpertApplication.DatabaseModel;
using ExpertApplication.DatabaseService;
using ExpertApplication.ViewModels;
using Ninject;

namespace ExpertApplication.Controllers
{
    public class HomeController : Controller
    {
        [Inject]
        private readonly IExpertContextManager _expertContextManager;

        public HomeController(IExpertContextManager expertContextManager)
        {
            _expertContextManager = expertContextManager;
        }

        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC 4 application.";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your quintessential app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your quintessential contact page.";

            return View();
        }

        public ActionResult Login(string uid, string first_name, string last_name, string photo,
            string photo_rec, string hash)
        {
            /*http://188.230.106.25/Home/Login?uid=22830147&first_name=Viktor&last_name=Dzundza&photo=http://vk.com/images/camera_a.gif&photo_rec=http://vk.com/images/camera_c.gif&hash=09fae5ecb5a414e47f7281216e5d9ed8*/

            ViewData["uid"] = uid;
            ViewData["first_name"] = first_name;
            ViewData["last_name"] = last_name;
            ViewData["photo"] = photo;
            ViewData["photo_rec"] = photo_rec;
            ViewData["hash"] = hash;
            _expertContextManager.AddUser(new User
                                              {
                                                  FirstName = first_name,
                                                  Hash = hash,
                                                  IsLogged = true,
                                                  LastName = last_name,
                                                  Photo = photo,
                                                  PhotoRec = photo_rec,
                                                  Uid = uid
                                              });
            return RedirectToAction("Index");
            // return View();
        }


        public ActionResult StartTest(int startedLevel = 0)
        {
            var questions = _expertContextManager.GetQuesitonForLevel(startedLevel);
            return View(questions);
        }

        [HttpPost]
        public ActionResult ProcessAnswers(IList<QuestionViewModel> answerForQuesiton)
        {

            throw new NotImplementedException();
        }
    }
}